package com.pigotech.ptwo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.pigotech.ptwo.R;
import com.pigotech.ptwo.constant.Constant;
import com.pigotech.ptwo.entity.NormalVideo;

import java.util.List;

/**
 * Created by ghb on 2018/3/28.
 */

public class NormalVideoAdapter extends BaseAdapter {

    private List<NormalVideo> list = null;
    private Context context = null;
    private LayoutInflater inflater = null;


    public NormalVideoAdapter (List<NormalVideo> list,Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_video_list_mini, null);
            viewHolder.iv_normal_video_mini = (ImageView)convertView.findViewById(R.id.iv_normal_video_mini);
            viewHolder.tv_video_name = (TextView) convertView.findViewById(R.id.tv_video_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        NormalVideo normalVideo = list.get(position);
        Glide.with(context).load("http://" + Constant.IP_ADDRESS + Constant.NORMAL_VIDEO_TUMB_DIRECTORY + normalVideo.getFilename().replace("A.MP4","T.JPG")).into(viewHolder.iv_normal_video_mini);
        viewHolder.tv_video_name.setText(normalVideo.getFilename());
        return convertView;
    }

    class ViewHolder{
        ImageView iv_normal_video_mini;
        TextView tv_video_name;
    }
}
